# -*- coding:utf-8 -*-
import time

from selenium.webdriver.common.by import By

from base.base import Base
from handle.handle_yaml import park_manage_yaml_handle
from handle.handle_log import log


class ParkManage(Base):
    """
    园区管理
    """
    def __int__(self, driver):
        super().__init__(driver)
        self.driver = driver

    def create_part(self, baseuse="no"):
        """

        :param url:
        :param link:
        :return:
        """
        ele = park_manage_yaml_handle()
        # 进入园区人员界面
        self.driver_.get(
            ele['park_manage']['member']['page']
        )
        log.debug("进入人员管理界面")

        # 点击项目管理
        self.find_element(
            By.XPATH,
            ele['park_manage']['member']['newpart'][0]
        ).click()
        log.debug("点击项目管理")

        # 输入项目名称
        self.find_element(
            By.XPATH,
            ele['park_manage']['member']['newpart'][1]
        ).send_keys("自动化专用数据")
        log.debug("输入项目名称")

        # 点击添加
        check_click = self.check_click(
            By.XPATH,
            ele['park_manage']['member']['newpart'][2]
        )
        check_click.click()
        log.debug("点击添加")

        time.sleep(1)

        # 验证新建部门是否成功
        ele_list = self.find_elements(
            By.XPATH,
            ele['park_manage']['member']['newpart'][3]
        )
        time.sleep(1)
        if baseuse == "no":
            for i in ele_list:
                if i.text == "自动化专用数据（0）人":
                    i.click()
                    self.find_element(
                        By.XPATH,
                        ele['park_manage']['member']['newpart'][4]
                    ).click()
                    log.debug("删除新建保持数据复用性")
                    time.sleep(1)
                    check_delete = self.check_click(
                        By.XPATH,
                        ele['park_manage']['member']['newpart'][5]
                    )
                    check_delete.click()
                    log.debug("删除添加部门")
                    return i.text





